import QtQuick 2.11
import QtGraphicalEffects 1.0

Item {
    signal buttonClicked(var mouse)

    property alias source: imageButton.source
    //property alias effectSource: soundEffectClick.source
    property var soundEffectClick: null
    property bool bEffectOn: true

    id: root
    width: 200
    height: 100

    Image {
        id: imageButton
        anchors.fill: parent
    }

    //颜色遮罩(不可用时黑色,source必须和本对象同一层次!!!)
    ColorOverlay {
        id: colorOverlay
        visible: false
        anchors.fill: imageButton
        source: imageButton
        color: root.enabled ? "#40FFFFFF" : "#40000000"
        //parent: root
    }

    /*
    SoundEffect {
        id: soundEffectClick
        //source: Global._FixLocalPath_"Media/Sounds/Effects/Harm.wav")
        //loops: SoundEffect.Infinite
        loops: 1
    }*/

    MouseArea {
        anchors.fill: parent
        hoverEnabled: true

        enabled: root.enabled
        onEntered: {
            if(enabled) {
                cursorShape = Qt.PointingHandCursor;
                colorOverlay.visible = true;
            }
        }
        onExited: {
            if(enabled) {
                cursorShape = Qt.ArrowCursor;
                colorOverlay.visible = false;
            }
        }
        onClicked: {
            if(bEffectOn && soundEffectClick != null)soundEffectClick.play();

            buttonClicked(mouse);
        }
    }

    QtObject {
        id: _private

    }

    onEnabledChanged: {
        if(enabled == false)
            colorOverlay.visible = true;
        else
            colorOverlay.visible = false;

    }

    Component.onCompleted: {
    }
}
